/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: GroupBy.java   2020-10-05 14-38-16
 * Author: Evan
 */
package cn.datacare.orm.query.group;

import cn.datacare.orm.util.Separator;
import cn.datacare.orm.util.StringUtils;

import static cn.datacare.orm.util.Separator.COMMA;
import static cn.datacare.orm.util.StringUtils.SPACE;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-05 14-38-16
 * @since V1.0
 */
public class GroupBy {
    /**
     * GroupBy
     */
    public static final String GROUP_BY="GROUP BY ";
    /**
     * Having
     */
    public static final String HAVING="HAVING ";

    private StringBuilder builder=new StringBuilder(GROUP_BY);

    private Boolean start=true;

    public void add(String col){
        if(start){
            builder.append(col);
        }else{
            builder.append(COMMA).append(col);
        }
        builder.append(SPACE);
    }

    public String getGroupBy(){
        return builder.toString().trim();
    }


    public GroupBy addHaving(String sql){
        builder.append(HAVING).append(sql).append(SPACE);
        return  this;
    }
}
